//
//  YTETPorpertyController.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/8/14.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTETPorpertyController.h"
#import "YTExChangeCell.h"
#import "YTETAILogController.h"
#import "YTETAddrController.h"

#define kTableViewMargin 16
@interface YTETPorpertyController ()<UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *headerContentView;     // 头部视图
@property (weak, nonatomic) IBOutlet UIView *infoContentView;   // 用户信息视图
@property (weak, nonatomic) IBOutlet UIView *walletContentView;     // 以太钱包视图

@property (weak, nonatomic) IBOutlet UIView *exchangeContentView;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;    // 用户名

@property (weak, nonatomic) IBOutlet UILabel *userIDLabel;      // 用户ID

@property (weak, nonatomic) IBOutlet UILabel *userEnergyLabel;      // 用户算力



@property (weak, nonatomic) IBOutlet UILabel *etaiCountLabel;       // ETAI总数


@property(nonatomic ,strong)YTETAIPorpertyModel *model;

@end

@implementation YTETPorpertyController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置圆角
    [self setupConRadiusWithView:self.headerContentView];
    [self setupConRadiusWithView:self.infoContentView];
    [self setupConRadiusWithView:self.walletContentView];
    [self setupConRadiusWithView:self.exchangeContentView];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage dh_setNavImageName:@"倛袨1"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClick)];
    
    [self setupNav];
    // 加载数据
    [self loadData];
}

#pragma mark: - 星币明细 按钮监听
- (IBAction)ETAILogButtonClick
{
    YTETAILogController *vc = [[YTETAILogController alloc] init];
    [self.navigationController pushViewController:vc animated:true];
}
#pragma mark: - 地址管理 按钮监听
- (IBAction)addrButtonClick
{
    YTETAddrController *vc = [[YTETAddrController alloc] init];
    [self.navigationController pushViewController:vc animated:true];
}


- (void)setupNav
{
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"以太护照";
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.font = [UIFont boldSystemFontOfSize:15];
    titleLabel.textColor = UIColor.blackColor;
    self.navigationItem.titleView = titleLabel;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar
     setTitleTextAttributes:@{NSForegroundColorAttributeName : UIColor.whiteColor}];
}
#pragma mark: - 加载数据
- (void)loadData
{

    [YTNetworkManager.shareManager requestWithETAIInfoWithCompletion:^(YTETAIPorpertyModel *model, BOOL isSucc, NSString *error)
    {
        if (!isSucc) {
            [self.view showErrorWithTipStr:error];
            return ;
        }


        self.model = model;
        self.userNameLabel.text = model.display_name;
        self.userIDLabel.text = model.user_id;
        self.etaiCountLabel.text = model.money;
        self.userEnergyLabel.text = model.energy;
        [self.tableView reloadData];
        YTExChangeCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
        cell.exList = model.exList;
        
        
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            return 121;
            break;
        case 1:
            return 92;
        default:
            return (self.model.exList.count > 0) ? self.model.exList.count * 34 + 64 + kTableViewMargin : 64;
            break;
    }
}
#pragma mark: - 设置圆角的方法
- (void)setupConRadiusWithView:(UIView *)view
{
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 10;
}
// 返回按钮
- (void)backButtonClick
{
    [self.navigationController popViewControllerAnimated:true];
}

@end
